const mongoose = require("../utils/DB.js");
const classModel = require("./class.js");
//创建数据模型
let studentSchema = new mongoose.Schema({
    name: String,
    age: Number,
    gender: String,
    score: Number,
    address: String,
    class:{
        type: mongoose.Schema.Types.ObjectId,
        ref:"classModel"     //引用那个数据模型
    }
});
//映射数据模型
let studentModel = mongoose.model('studentModel', studentSchema, 'student');
//非连表查询
// let studentsRes = studentModel.find()
//连表查询 populate: 填充的字段 classid
// let studentsRes = studentModel.find().populate("class",'name')
// studentsRes.then((data)=>{
//     //console.log(data[0].classid._id,data[0].classid.name)
//     console.log(data);
// })
module.exports = studentModel